//
//  BasicViewController.m
//  SulitLoan
//
//  Created by 虞嘉伟 on 2025/2/24.
//  


#import "BasicViewController.h"
#import <YYKit.h>
#import <Masonry.h>

@interface BasicViewController ()

@end

@implementation BasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.backgroundColor = UIColor.whiteColor;
    self.tabBarController.tabBar.translucent = NO;
    self.fd_interactivePopDisabled = YES;
    
    [self.view addSubview:self.navBar];
    self.navBar.hidden = YES;
    self.navBar.layer.zPosition = 10;
    [self.navBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view);
        make.height.mas_equalTo(44+SAFE_AREA_INSETS.top);
    }];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.view bringSubviewToFront:self.navBar];
}
- (NavBar *)navBar {
    if (!_navBar) {
        _navBar = [NavBar new];
        _navBar.backgroundColor = UIColor.whiteColor;
        @weakify(self);
        _navBar.backBlock = ^{
            @strongify(self);
            [self.navigationController popViewControllerAnimated:YES];
        };
    }
    return _navBar;
}

- (void)showNavBar:(NSString *)title {
    self.fd_prefersNavigationBarHidden = YES;
    self.navBar.hidden = NO;
    self.navBar.titleLabel.text = title;
}

- (void)showNavBar:(NSString *)title backBlock:(dispatch_block_t)backBlock {
    self.fd_prefersNavigationBarHidden = YES;
    self.navBar.hidden = NO;
    self.navBar.titleLabel.text = title;
    [self.navBar.backButton jk_addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        !backBlock ?: backBlock();
    }];
}

- (void)hidenNavBar {
    self.navBar.hidden = YES;
    self.fd_prefersNavigationBarHidden = YES;
}

- (void)hidenBackButton {
    self.navBar.backButton.hidden = YES;
}

@end
